<?php
declare (strict_types=1);

namespace app\api\controller\v5;

use app\common\models\Datum;
use app\common\models\DatumCate;
use app\common\models\Record;
use app\common\models\Room;
use app\common\models\Unit as UnitModel;
use function Couchbase\defaultDecoder;

class Unit extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */

    public function index()
    {
       // $id = input('id/d', 0);
        $type = input('type/d', 1);
        //$room_id = input('room_id', 0);
        if ($type == 1) {
            $classs = ['三年级','四年级','五年级','六年级'];
        } else {
            $classs = ['七年级','八年级','九年级',];
        }
        $room = Room::whereIn('title', $classs)
            ->field('id,title')
            ->select();
        foreach ($room as &$v) {
            $v['unit'] = UnitModel::where(['room_id' => $v['id'], 'status' => 1])
                ->field('id,title')
                ->select();
        }
        return sucessMsg(200, '获取成功', ['room' => $room]);
    }
}
